package com.view;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
import java.sql.SQLException;

import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;

public class Frame extends JFrame implements ActionListener{
	/**
	 * 
	 */
	private static final long serialVersionUID = 23123L;
	private File srcFile;
	private JTextField jtf;
	public Frame() {
		setVisible(true);
		setLocationRelativeTo(null);
		setLayout(null);
		setSize(500, 500);
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		JButton btn=new JButton("...");
		btn.setBounds(0, 0, 100, 100);
		btn.addActionListener(this);
		jtf=new JTextField();
		jtf.setBounds(200, 0, 100, 100);
		JButton btn1=new JButton("提交");
		btn1.setBounds(200, 300, 100, 50);
		btn1.addActionListener(this);
		add(btn1);
		add(jtf);
		add(btn);
		
	}
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			
			@Override
			public void run() {
				new Frame();
				
			}
		});
	}
	@Override
	public void actionPerformed(ActionEvent e) {
		String com=e.getActionCommand();
		if(com.equals("...")){
			JFileChooser jfc=new JFileChooser();
			int f=jfc.showOpenDialog(this);
			if(f==JFileChooser.APPROVE_OPTION){
				srcFile=jfc.getSelectedFile();
				jtf.setText(srcFile.getPath());
			}
		}
		if(com.equals("提交")){
			ExcelDate ed=new ExcelDate();
			try {
				ed.insert(jtf.getText());
			} catch (IOException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			} catch (SQLException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			} catch (Exception e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
		}
	}
}
